import express from "express";
import { PrismaClient, Prisma } from ".prisma/client";
import { Check, CreateId, Result, Time } from "@/utils";

const prisma = new PrismaClient();
const router = express.Router();

router.post("/create", async (req, res) => {
   const { name, category, level } = req.body as Majors.Create;
   if (!Check.Required([name, category, level])) return res.send(Result.Error("参数错误"));

   const { userId } = req;
   const id = await CreateId.One("mp_majors");
   const majors = await prisma.mp_majors.create({
      data: {
         id,
         name,
         level,
         category,
         status: "OPEN",
         created_by: userId,
         created_time: Time.Now()
      }
   });

   res.send(Result.OK());
});

router.post("/delete", async (req, res) => {});

router.post("/update", async (req, res) => {});

router.post("/search", async (req, res) => {});

export const majors = router;
